package com.cardmanager.pro.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.cardmanager.pro.pojo.ConsumeTaskPOJO;
@Repository
public interface ConsumeTaskPOJORepository extends JpaRepository<ConsumeTaskPOJO, Long>,JpaSpecificationExecutor<ConsumeTaskPOJO>{

	@Query("select count(*) from ConsumeTaskPOJO consumeTaskPOJO where consumeTaskPOJO.userId=:userId and consumeTaskPOJO.creditCardNumber =:creditCardNumber and consumeTaskPOJO.taskStatus=:taskStatus")
	int queryTaskStatusCount(@Param("userId") String userIdStr, @Param("creditCardNumber") String creditCardNumber, @Param("taskStatus") int taskStatus);

	@Query("select consumeTaskPOJO from ConsumeTaskPOJO consumeTaskPOJO where consumeTaskPOJO.taskType=:taskType and consumeTaskPOJO.taskStatus=:taskStatus and consumeTaskPOJO.executeDateTime <=:nowTime and consumeTaskPOJO.executeDate = :executeDate")
	List<ConsumeTaskPOJO> findTaskTypeAndTaskStatusRepaymentTask(@Param("taskType") int taskType, @Param("taskStatus") int taskStatus, @Param("nowTime") String nowTime, @Param("executeDate") String executeDate);

	@Query("select count(*) from ConsumeTaskPOJO consumeTaskPOJO where consumeTaskPOJO.userId=:userId and consumeTaskPOJO.creditCardNumber =:creditCardNumber and consumeTaskPOJO.taskStatus=:taskStatus and consumeTaskPOJO.taskType=:taskType")
	int queryTaskStatusAndTaskTypeCount(@Param("userId") String userId, @Param("creditCardNumber") String creditCardNumber, @Param("taskStatus") int taskStatus, @Param("taskType") int taskType);

	@Query("select count(*) from ConsumeTaskPOJO consumeTaskPOJO where consumeTaskPOJO.userId=:userId and consumeTaskPOJO.creditCardNumber =:creditCardNumber and consumeTaskPOJO.orderStatus=:orderStatus and consumeTaskPOJO.taskType=:taskType")
	int queryOrderStatusAndTaskTypeCount(@Param("userId") String userId, @Param("creditCardNumber") String creditCardNumber, @Param("orderStatus") int orderStatus, @Param("taskType") int taskType);

	List<ConsumeTaskPOJO> findByRepaymentTaskId(String repaymentTaskId);

	ConsumeTaskPOJO findByOrderCode(String orderCode);

	@Query("select consumeTaskPOJO from ConsumeTaskPOJO consumeTaskPOJO where consumeTaskPOJO.userId=:userId and consumeTaskPOJO.creditCardNumber =:creditCardNumber and consumeTaskPOJO.taskType=:taskType and consumeTaskPOJO.taskStatus=:taskStatus")
	ConsumeTaskPOJO findByTaskTypeAndTaskStatusConsumeTaskPOJO(@Param("userId") String userId, @Param("creditCardNumber") String creditCardNumber, @Param("taskType") int taskType, @Param("taskStatus") int taskStatus);

	ConsumeTaskPOJO findByConsumeTaskId(String consumeTaskId);
}
